package logic

import (
	"context"
	"user/internal/svc"
	"user/models/mysql"
	"user/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *user.GoodsAddRequest) (*user.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	goods := mysql.Good{
		GoodsId: int(in.GoodsId),
		UserId:  int(in.UserId),
		Num:     int(in.Num),
		Stock:   int(in.Stock),
	}
	mysql.DB.Debug().Create(&goods)

	return &user.GoodsAddResponse{UserId: in.UserId}, nil
}
